package cn.iocoder.yudao.module.book.dal.mysql.collect;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.book.dal.dataobject.collect.CollectDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.book.controller.admin.collect.vo.*;
import org.apache.ibatis.annotations.Param;

import javax.validation.Valid;

/**
 * 收藏 Mapper
 *
 * @author xi
 */
@Mapper
public interface CollectMapper extends BaseMapperX<CollectDO> {

    default PageResult<CollectDO> selectPage(CollectPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<CollectDO>()
                .eqIfPresent(CollectDO::getCollectId, reqVO.getCollectId())
                .eqIfPresent(CollectDO::getUserId, reqVO.getUserId())
                .eqIfPresent(CollectDO::getBookId, reqVO.getBookId())
                .eqIfPresent(CollectDO::getCollectionId, reqVO.getCollectionId())
                .betweenIfPresent(CollectDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(CollectDO::getCollectionId));
    }

    Integer deleteByBookId(@Param("bookId") Integer bookId,@Param("userId") Long userId);

    List<CollectDO> selectByUserId(@Param("userId") Long userId);

    Integer insertCollect(@Param("bookId") Integer bookId,@Param("userId") Long userId,@Param("collectionId") Integer collectionId,@Param("createTime") String createTime);

    Integer existsByBookId(@Param("bookId") Integer bookId,@Param("userId") Long userId);

    CollectDO selectByBookId(@Param("bookId") Integer bookId,@Param("userId") Integer userId);

    void updateRecord(@Param("id") Integer collectId);

    List<CollectDO> selectByUserIdAndType(@Param("userId") Long userId, @Param("type") String type);

    Integer deleteByCollectionId(@Param("collectionId") Integer collectionId, @Param("userId") Long userId);

    Integer existsByCollectionId(@Param("collectionId") Integer collectionId, @Param("userId") Long userId);

    Integer insertCollectCollection(@Param("collectionId") Integer collectionId, @Param("userId") Long userId, @Param("createTime") String createTime);

    Integer cleanDuplicatesByUserId(@Param("userId") Long userId);

//    Integer existsByBookId(@Param("bookId") Integer bookId, @Param("userId") Integer userId);
}